package com.czk.bootlettuce.controller;

import com.czk.bootlettuce.config.RedisSequenceFactory;
import com.czk.bootlettuce.utils.TimeEndUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.support.atomic.RedisAtomicLong;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author:ChenZhangKun
 * @Date: 2021/12/17 16:16
 */
@RequestMapping("/get")
@RestController
public class GetNumController {
    public static final String sMsgSequenceKeyFormat = "hello";
   // @Autowired
    private RedisSequenceFactory redisSequenceFactory;
    @Autowired
    private StringRedisTemplate redisTemplate;
    @GetMapping("/num")
    public Long getNum() {
        RedisAtomicLong counter = new RedisAtomicLong(sMsgSequenceKeyFormat, redisTemplate.getConnectionFactory());
        counter.expireAt(TimeEndUtil.getTodayEndTime());
        return counter.incrementAndGet();
    }
}
